
var vm = new Vue({
    el: "#app",
    data:
        {
            loginUser:'',
            userName: 'admin',
            pws: '',
        },
    // 方法存放区
    methods: {
        login() {
            if (vm.userName == '' || vm.pws == '') {
                alert("请输入用户和密码");
            }
            else{
                    axios({
                        method: 'POST',
                        url: '/user/login',
                        params: {
                            "name": vm.userName,
                            "password": vm.pws,
                        }
                    }).then(function (res) {
                        console.log(res)
                        vm.loginUser = res.data;
                        if (vm.loginUser.msg == null || vm.loginUser.msg == "") {
                            window.location.href = "main.html"

                        } else {
                            alert(vm.loginUser.msg);
                        }

                    }).catch(function (reason) {
                        console.log(reason);
                    })
            }
        },

        test() {
            if (vm.userName == '') {
                alert("请输入用户");
            } else {
                axios({
                    method: 'POST',
                    url: '/exist',
                    params: {
                        "name": vm.userName,
                    }
                }).then(function (res) {
                    if (res.data== "ok") {
                    } else {
                        alert( "不存在此用户");
                        $(".loginuser").val("")
                    }
                }).catch(function (reason) {
                    console.log(reason);
                })
            }
        },
    },
    //页面加载完自动执行
    mounted() {

    }
});





